//权限管理模块的接口
import request from '@/utils/request'
import type { MenuResponseData, RoleData, RoleResponseData } from './type'

enum API {
    //获取全部职位的接口
    ALLROLE_URL = 'admin/acl/role/',
    //新增职位的接口
    ADDROLE_URL = 'admin/acl/role/save',
    //更新已有的职位的接口
    UPDATEROLE_URL = 'admin/acl/role/update',
    //获取全部的菜单与按钮数据的接口
    ALLPERMISSION_URL = 'admin/acl/permission/toAssign/',
    //给相应的职位分配权限的接口
    SETPERMISSION_URL = 'admin/acl/permission/doAssign/',
    //删除已有职位的接口
    DELETEROLE_URL = 'admin/acl/role/remove/'
}

//获取全部职位的接口方法
export const reqAllRoleList = (pageNo: number, limit: number, roleName: string) =>
    request.get<any, RoleResponseData>(API.ALLROLE_URL + `${pageNo}/${limit}/?roleName=${roleName}`)
//新增职位和更新已有职位的接口方法
export const reqAddOrUpdateRole = (data: RoleData) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEROLE_URL, data)
    } else {
        return request.post<any, any>(API.ADDROLE_URL, data)
    }
}
//获取全部的菜单与按钮数据的接口方法
export const reqAllMenuList = (roleId: number) => request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + roleId)
//给相应的职位分配权限的接口方法
export const reqSetPermission = (roleId: number, permissionId: number[]) =>
    request.post(API.SETPERMISSION_URL +`?roleId=${roleId}&permissionId=${permissionId}`)
//删除已有职位的接口方法
export const reqDeleteRole = (roleId: number) => request.delete<any, any>(API.DELETEROLE_URL + roleId)

